﻿/**
 * 進入房間命令
 * 
 * @author LuoDong
 * @email luo4521@online.net.tw
 * 2010-2-7 10:03
 */
package com.addcn.texas.control {
	import com.addcn.fog.control.ICommand;
	import com.addcn.fog.control.SimpleCommand;
	
	import com.addcn.texas.model.*;	
	import com.addcn.texas.view.*;	
	import com.addcn.common.utils.DestroyMemory;
	
	public class joinRoomCommand extends SimpleCommand implements ICommand {
		
		public override function execute(r_data:Object = null):void {		
			var _model : Object;
			if(r_data.cmd == "join"){
				_model = modelLocator.getModel(HallModel);
				if(_model != null){
					_model.joinRoom(r_data.type, r_data.rid);
				}	
									
			}else {
				
				viewLocator.addView(RoomView);											
				viewLocator.addView(GamePropsView);
				viewLocator.addView(PokerView);
				//viewLocator.addView(ChipsView);
				viewLocator.addView(ChipView);
				viewLocator.addView(RoomUserView);
				
	
				viewLocator.removeView(HallView);
				viewLocator.removeView(FriendsView);
				viewLocator.removeView(StartupView);
				//注冊房間數據模型
				if (!modelLocator.hasModel(RoomModel)) {
					modelLocator.addModel(RoomModel); 																		
				}	
				//注冊房間中玩家數據模型	
				if (!modelLocator.hasModel(RoomUserModel)) {
					modelLocator.addModel(RoomUserModel); 			
				}
				//注冊游戏數據模型				
				if (!modelLocator.hasModel(GameInfoModel)) {
					modelLocator.addModel(GameInfoModel);												
				}			
				//移除大厅数据模型	
				modelLocator.removeModel(HallModel); 
				modelLocator.removeModel(UserInfoModel);
				DestroyMemory.clear();
			}
		}

	}
}
